﻿using OAuth;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace DropboxLib
{
    class TestClass
    {
        static void Main()
        {
            /*
            //Start Request Token
            var consumerKey = "key";
            var consumerSecret = "access";

            var uri = new Uri("https://api.dropbox.com/1/oauth/request_token");


            // Generate a signature
            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timeStamp = oAuth.GenerateTimeStamp();
            string parameters;
            string normalizedUrl;
            string signature = oAuth.GenerateSignature(uri, consumerKey, consumerSecret,
                String.Empty, String.Empty, "GET", timeStamp, nonce, OAuthBase.SignatureTypes.HMACSHA1,
                out normalizedUrl, out parameters);

            signature = HttpUtility.UrlEncode(signature);

            StringBuilder requestUri = new StringBuilder(uri.ToString());
            requestUri.AppendFormat("?oauth_consumer_key={0}&", consumerKey);
            requestUri.AppendFormat("oauth_nonce={0}&", nonce);
            requestUri.AppendFormat("oauth_timestamp={0}&", timeStamp);
            requestUri.AppendFormat("oauth_signature_method={0}&", "HMAC-SHA1");
            requestUri.AppendFormat("oauth_version={0}&", "1.0");
            requestUri.AppendFormat("oauth_signature={0}", signature);

            var request = (HttpWebRequest)WebRequest.Create(new Uri(requestUri.ToString()));
            request.Method = WebRequestMethods.Http.Get;

            var response = request.GetResponse();

            var queryString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            var parts = queryString.Split('&');
            var token = parts[1].Substring(parts[1].IndexOf('=') + 1);
            var tokenSecret = parts[0].Substring(parts[0].IndexOf('=') + 1);

            //End Request Token

            Start Authorize
            Opens browser with https connection to permit the app manipulate and 
            process downloads/uploads requests 
            var queryString1 = String.Format("oauth_token={0}", token);
            var authorizeUrl = "https://www.dropbox.com/1/oauth/authorize?" + queryString1;
            Process.Start(authorizeUrl);
            //End Authorize
            */

            DropBoxLib conn = new DropBoxLib();

            conn.ReqTokenAuth("key", "access");
            Console.WriteLine("Linking API to your dropbox account.Accept(browser window) and press any key to continue.");
            Console.ReadKey();

            conn.fullAcess("key", "access");
            

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}
